package com.aoyy.dao;

import java.util.List;
import org.springframework.stereotype.Repository;
import com.aoyy.model.Board;
import com.aoyy.util.Page;
/**=========================================================================================
 * DAO class <code>BoardDao</code>
 * @author this author
 * @date 2017-08-06
 * ========================================================================================== */
@Repository
public class BoardDao extends BaseDao<Board> {
	public Board queryBoardByBoardId(int boardId) {
		String hql = "from Board where boardId = " + boardId;
		@SuppressWarnings("rawtypes")
		List list = this.find(hql);
		if (list != null && !list.isEmpty()) {
			return (Board) list.get(0);
		}
		return null;
	}
	
	public Board queryBoardByBoardName(String boardName) {
		String hql = "from Board where boardName = '" + boardName + "'";
		@SuppressWarnings("rawtypes")
		List list = this.find(hql);
		if (list != null && !list.isEmpty()) {
			return (Board) list.get(0);
		}
		return null;
	}
	
	// Query other board with same board name to given board   
	public Board queryOtherBoardWithSameName(Board board) {
		String hql = "from Board where boardName = '" + board.getBoardName() + "' and boardId != " + board.getBoardId();
		@SuppressWarnings("rawtypes")
		List list = this.find(hql);
		if (list != null && !list.isEmpty()) {
			return (Board) list.get(0);
		}
		return null;
	}
	
	// Paged Query boards 
	public Page pagedQuery(int pageNo, int pageSize) {
		String hql = "from Board";
		return this.pagedQuery(hql, pageNo, pageSize);		
	}

}
